/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: Lenovo
 * Date: 2025-08-15
 * Time: 1:00
 */
//https://leetcode.cn/problems/container-with-most-water/description/
public class Test {
    public static int maxArea(int[] arr) {
        int p1=0;
        int p2=arr.length-1;
        int number=(p2-p1)*Math.min(arr[p1],arr[p2]);
        int n;
        int s1=arr[p1];
        int s2=arr[p2];
        while(p1<p2){
            if(s1<=s2){
                while(p1<p2&&arr[p1]<=s1){
                    p1++;
                }
                s1=arr[p1];
            }
            else{
                while(p1<p2&&arr[p2]<=s2){
                    p2--;
                }
                s2=arr[p2];
            }
            n=(p2-p1)*Math.min(s1,s2);
            if(n>number){
                number=n;
            }
        }
        return number;
    }
    public static void main(String[] args) {
        int[] arr={1,8,6,2,5,4,8,3,7,1};
        System.out.println(maxArea(arr));

    }
}
